<!--
 * @Author: your name
 * @Date: 2022-03-30 10:41:34
 * @LastEditTime: 2022-03-30 14:29:29
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\代理模式220330.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>代理模式</title>
</head>

<body>
  <script>
    // 先申明一个奶茶妹对象
    var TeaAndMilkGirl = function (name) {
      this.name = name;
    };
    // 这是京东ceo先生
    var Ceo = function (girl) {
      this.girl = girl;
      // 送结婚礼物 给奶茶妹
      this.sendMarriageRing = function (ring) {
        console.log("Hi " + this.girl.name + ", ceo送你一个礼物：" + ring);
      }
    };
    // 京东ceo的经纪人是代理，来代替送
    var ProxyObj = function (girl) {
      this.girl = girl;
      // 经纪人代理送礼物给奶茶妹
      this.sendGift = function (gift) {
        // 代理模式负责本体对象实例化
        (new Ceo(this.girl)).sendMarriageRing(gift);
      }
    };
    // 初始化
    var proxy = new ProxyObj(new TeaAndMilkGirl("奶茶妹"));
    proxy.sendGift("结婚戒"); // Hi 奶茶妹, ceo送你一个礼物：结婚戒
  </script>
</body>

</html>